{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T10:47:50.757769Z",
     "start_time": "2020-10-21T10:47:50.752062Z"
    }
   },
   "outputs": [],
   "source": [
    "import pickle\n",
    "def upickle(file):\n",
    "    fo=open(file,'rb')\n",
    "    dict=pickle.load(fo,encoding='latin1')\n",
    "    fo.close()\n",
    "    return dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T10:56:12.773838Z",
     "start_time": "2020-10-21T10:56:12.639748Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "def clean(data):\n",
    "    imgs=data.reshape(data.shape[0],3,32,32)\n",
    "    grayscale_imgs=imgs.mean(1)\n",
    "    cropped_imgs=gray_imgs[:,4:28,4:28]\n",
    "    img_data=cropped_imgs.reshape(data.shape[0],-1)\n",
    "    img_size=np.shape(img_data)[1]\n",
    "    means=np.mean(img_data,axis=1)\n",
    "    meansT=means.reshape(len(means),1)\n",
    "    stds=np.std(img_data,axis=1)\n",
    "    stdsT=stds.reshape(len(stds),1)\n",
    "    adj_stds=np.maximun(stdsT,1.0/np.sqrt(imgs_size))\n",
    "    normalized=(img_data-meanT)/adj_stds\n",
    "    return normalized\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
